﻿@using HotelRegistrationSystem.DAL;
@model HotelRegistrationSystem.Models.RoomReservesManageModel

@{
	ViewBag.Title = "RoomReservations";
}

<h2>RoomReservations</h2>

<table>
	<thead>
		<tr>
			<th colspan="2">
				@Html.LabelFor(model => model.HotelName)
				@Html.DisplayFor(model => model.HotelName)
			</th>
			<th colspan="3">
				@Html.LabelFor(model => model.RoomName)
				@Html.DisplayFor(model => model.RoomName)
			</th>
		</tr>
		<tr>
			<th>Username</th>
			<th>Beds</th>
			<th>StartDate</th>
			<th>EndDate</th>
			<th>Accept/Cancel</th>
		</tr>
	</thead>
	<tbody>
		@foreach (var reservation in Model.RoomReservations)
		{
			<tr>
				<td>
					@reservation.Username
				</td>
				<td>
					@reservation.Beds
				</td>
				<td>
					@reservation.StartDate
				</td>
				<td>
					@reservation.EndDate
				</td>
				<td>
					<div class="controlButtonsHolder">
								@if (reservation.ReservationStatusId == 1 || reservation.ReservationStatusId == 4)
					{
						<div class="leftButton">
						@using (Html.BeginForm(new RouteValueDictionary(new
						{
							roomId = Model.RoomId,
							reservationId = reservation.ReservationId,
							newReservationStatusId = 2
						})))
						{
							<input type="submit" class="button small radius" value="Accept" />
						}
						</div>
						<div class="rightButton">
						@if (reservation.ReservationStatusId != 3 && DateTime.Now < reservation.StartDate.AddDays(-2))
						{
							using (Html.BeginForm(new RouteValueDictionary(new
							{
								roomId = Model.RoomId,
								reservationId = reservation.ReservationId,
								newReservationStatusId = 3
							})))
							{
								<input type="submit" class="button small radius" value="Cancel" />
							}
						}
						</div>
					}
					else
					{
						<text>@ReservationsDAL.GetReservationsStatusName(reservation.ReservationStatusId)</text>
					}
					</div>
				</td>
			</tr>
		}
	</tbody>
</table>
